1. Field of the Invention
The present invention relates to systems and methods for allocating memory and, more particularly, to systems and methods for allocating memory by partitioning the memory.
2. Description of the Related Art
Most data processing systems have a fixed amount of memory for running computer programs. Although a larger amount of memory would increase the speed and flexibility of the system, it would also increase the size and cost of the system as well. This tradeoff is especially true for embedded data processing systems, such as computerized fax machines and telephone answering machines, since they typically have a limited amount of memory to minimize size and cost.
Unfortunately, smaller memories tend to become severely fragmented. Memory becomes fragmented when it contains a random assortment of free memory blocks located between allocated memory blocks. This usually occurs after memory has been repeatedly allocated and deallocated (i.e., freed). FIG. 1 illustrates an example of a fragmented memory array 100 containing blocks of free memory 110 and blocks of allocated memory 120. As shown in FIG. 1, the amount of free memory is broken up into various sizes of free memory blocks 110.
Fragmentation causes several problems. First, fragmentation makes the memory less efficient by breaking up the free memory into blocks of various sizes. Thus, a memory system must search for an adequately sized block of free memory before it can store data of a certain size. This increases processing time, typically by an amount proportional to the number of free blocks. Second, fragmentation often causes a loss of overall effective memory since some of the free blocks will be too small to be of any use.
One way to reduce fragmentation is by having a memory system that allocates memory in an optimum manner based on the particularly memory requirements of the overall data processing system. This approach is nearly impossible, however, since there is no way to predict the exact memory requirements for each program using the memory. Even if the system could determine these memory requirements, the increased amount of processing time to implement this approach would be overly burdensome.
A conventional method for allocating memory is the xe2x80x9cfirst-fitxe2x80x9d approach. This approach uses a free list, which is a file created by the memory system that comprises a linked-list of pointers to each block of free memory in the memory array. The pointers are typically ordered by the memory addresses of the corresponding free memory blocks. Thus, the first pointer of the free list points to the first free memory block in the array, while the second pointer points to the second free memory block, and so on. For purposes of illustration, FIG. 1 shows such a free list 130 for memory array 100.
Under the first-fit approach, the memory system traverses the free list until it encounters a pointer to a block large enough to store the data. The memory system usually uses a linear search to traverse the free-list. Accordingly, the longer the free list (i.e., the greater the number of free memory blocks), the longer will be the average time to locate the first block of sufficient size. Although this approach is relatively fast, it is not very efficient. In particular, the first-fit approach simply allocates the data to the first free memory block capable of storing the data, rather than to the free memory block that most closely matches the data size.
Therefore, it is desirable to have a memory system that can allocate memory without causing fragmentation. Furthermore, it is desirable to have a memory system that can reduce fragmentation efficiently and without taking a large amount of processing time.
Systems and methods consistent with the present invention reduce fragmentation of a memory array by efficiently allocating memory to the memory array, and without requiring a large amount of processing time.
In accordance with the purposes of the invention as embodied and broadly described herein, a memory management system and method consistent with the present invention collects memory statistics to determine memory block sizes frequently used in the memory array. The system uses these statistics to partition the memory array into a memory subheap and a main heap. The system then determines whether to allocate or deallocate a memory block of the memory subheap based on a memory block size associated with the memory subheap.
Both the foregoing general description and the following detailed description are exemplary and are intended to provide further explanation of the invention as claimed.